﻿
// LockclipDlg.h: 头文件
//

#pragma once
#include "afxdialogex.h"
#include "SerialCom.h"
#include "ExceJs.h"
#include "CTolerance.h"
#include <json.h>
#include <iostream>
#include <sstream>
#include <string>
#include "DataBase.h"

#ifdef _DEBUG
#pragma comment(lib,"libcrypto.lib")
#pragma comment(lib,"libssl.lib")
#else
#pragma comment(lib,"libcrypto.lib")
#pragma comment(lib,"libssl.lib")
#endif

class CLockclipDlgAutoProxy;

// CLockclipDlg 对话框
class CLockclipDlg : public CDHtmlDialog
{
	DECLARE_DYNAMIC(CLockclipDlg);
	friend class CLockclipDlgAutoProxy;
	// 构造
public:
	//成员变量
	Common::ExceJs m_ExceJs;
	CStringArray m_paras;
	CString m_parStr;
	CString m_team_count;
	CSerialCom m_ser_laser;
	CSerialCom m_ser_motor;
	CSerialCom m_ser_lock;
	BOOL m_ser_blaser;
	BOOL m_ser_bmotor;
	BOOL m_ser_block;
	BOOL m_bTimerIsActive;
	BOOL m_bAlert;
	// 1 杆径， 2 锁夹槽，3 锥面
	int m_sys_model;
	int m_sys_command;
	int m_proId;
	int m_lock_port;
	int m_laser_port;
	int m_motor_port;
	int m_dev_state;
	int m_but_state;

	int m_ratio_dist;
	LONG m_reslut_dist;
	LONG m_cur_dist;

	int m_forward;
	int m_reverse;
	int m_inch;
	int m_motor_time;
	int m_motor_point;
	int m_gather_count;
	int m_proof_count;

	int m_proof_minute;
	int m_gather_time;
	int m_team_quantity;
	int m_each_time;

	Json::Value m_userInfo;
	std::string m_home_html[3] = { "rodDemeter.html", "lockClampSlot.html", "conicalsurface.html" };
	UCHAR m_revBuff[BUF_LEN];
	char m_lockBuff[8] = { 99, 48, 48, 48, 48, 49, 48, 48};
	char m_rodBuff[8] = { 107, 48, 48, 48, 48, 48, 48, 48 };
	char m_un_str[BUF_LEN];
	char m_sendBuff[128];
	static char m_detect_command[6];

	double param1_standard_value;
	double param1_standard_upper;
	double param1_standard_lower;
	double param2_standard_value;
	double param2_standard_upper;
	double param2_standard_lower;
	double param3_standard_value;
	double param3_standard_upper;
	double param3_standard_lower;

	std::vector<BSTR>  m_s_jsonString;//报警事件
	int data_num;

	std::vector<DataRecord> last_ten_items;
	double m_s_mean; //X均值
	int m_p_sign = 0;;
	int m_p_sign_json = 0;;
	std::vector<double>  m_p1_datas;
	std::vector<double>  m_p2_datas;
	std::vector<double>  m_p3_datas;
	std::vector<double>  m_p1_mean;
	std::vector<double>  m_p2_mean;
	std::vector<double>  m_p3_mean;

	std::vector<double>  m_s1_datas;
	std::vector<double>  m_s2_datas;
	std::vector<double>  m_s3_datas;
	std::vector<double>  m_s4_datas;
	std::vector<double>  m_s5_datas;
	std::vector<double>  m_s6_datas;
	std::vector<double>  m_s7_datas;
	std::vector<double>  m_s8_datas;
	std::vector<double>  m_s9_datas;

	std::vector<int> m_data_rod;
	std::vector<int> m_motor_points;
	std::vector<std::vector<double>> m_measure_data;

	CTolerance m_p1Tolerance;
	CTolerance m_p2Tolerance;
	CTolerance m_p3Tolerance;

	Monolateral m_mono1;
	Monolateral m_mono2;
	Monolateral m_mono3;

	CTolerance m_s1Tolerance;
	CTolerance m_s2Tolerance;
	CTolerance m_s3Tolerance;
	CTolerance m_s4Tolerance;
	CTolerance m_s5Tolerance;
	CTolerance m_s6Tolerance;
	CTolerance m_s7Tolerance;
	CTolerance m_s8Tolerance;
	CTolerance m_s9Tolerance;
	CTolerance m_s10Tolerance;

	//杆径判异上下限
	double m_rod_std_val;
	double rod1_m_up_A, rod1_m_ct_B, rod1_m_down_C;
	double rod2_m_up_A, rod2_m_ct_B, rod2_m_down_C;
	double rod3_m_up_A, rod3_m_ct_B, rod3_m_down_C;

	//锁夹槽判异上下限
	double s1_bt_m_up;
	double s1_bt_m_ct;
	double s1_bt_m_down;
	double s1_ct_m_up;
	double s1_ct_m_ct;
	double s1_ct_m_down;
	double s2_bt_m_up;
	double s2_bt_m_ct;
	double s2_bt_m_down;
	double s3_bt_m_up;
	double s3_bt_m_ct;
	double s3_bt_m_down;
	double s4_bt_m_up;
	double s4_bt_m_ct;
	double s4_bt_m_down;

	double s1_bc_m_up;
	double s1_bc_m_ct;
	double s1_bc_m_down;
	double s1_cc_m_down;
	double s2_bc_m_up;
	double s2_bc_m_ct;
	double s2_bc_m_down;
	double s3_bc_m_up;
	double s3_bc_m_ct;
	double s3_bc_m_down;
	double s4_bc_m_up;
	double s4_bc_m_ct;
	double s4_bc_m_down;

	bool allNormal_rob = true;
	bool allNorma2_rob = true;
	bool allNorma3_rob = true;

	int error_point1, error_point2, error_point3, error_point4, error_point5, error_point6, error_point7, error_point8, error_point9, error_point10;
	//int error_slot1, error_slot2, error_slot3, error_slot4, error_slot5;
	//std::vector<int>  slot_point1, slot_point2, slot_point3, slot_point4, slot_point5;
	std::vector<int>  allNorma_point1, allNorma_point2, allNorma_point3, allNorma_point4, allNorma_point5, allNorma_point6, allNorma_point7, allNorma_point8, allNorma_point9, allNorma_point10;

	bool allNormal_slot = true;
	bool allNorma2_slot = true;
	bool allNorma3_slot = true;
	bool allNorma4_slot = true;
	bool allNorma5_slot = true;
	bool allNorma6_slot = true;
	bool allNorma7_slot = true;
	bool allNorma8_slot = true;
	bool allNorma9_slot = true;
	bool allNorma10_slot = true;

	bool allNormal_cone = true;
	bool allNorma2_cone = true;

	double ct_cpk;
	double ct_ppk;
	double s1_bt_cp;
	double s1_bt_cpk;
	double s1_bt_pp;
	double s1_bt_ppk;
	double s1_bc_cpk;
	double s1_bc_ppk;
	double s2_bt_cp;
	double s2_bt_cpk;
	double s2_bt_pp;
	double s2_bt_ppk;
	double s2_bc_cpk;
	double s2_bc_ppk;
	double s3_bt_cp;
	double s3_bt_cpk;
	double s3_bt_pp;
	double s3_bt_ppk;
	double s3_bc_cpk;
	double s3_bc_ppk;
	double s4_bt_cp;
	double s4_bt_cpk;
	double s4_bt_pp;
	double s4_bt_ppk;
	double s4_bc_cpk;
	double s4_bc_ppk;

	std::ostringstream oss;
	std::string m_error_alarm;
	std::string m_sg_num;
	std::string m_hard_name;
	size_t m_pdata_lenght;
	size_t m_sdata_lenght;

	double m_roller;//压轮直径
	double m_roddia;//杆直接
	double m_pre_turns;//预转周数
	double m_cor_turns;//正传周数
	double m_wheelSpeed;//压轮速度

	NOTIFYICONDATA m_nid;
	CString _strTaskbarTip;
	CRect _tmpRect;
	bool _bVisible;

	CWinThread* m_Thread;
	int m_motor_potion;
	char m_motor_run_a;
	char m_motor_run_w;
	char m_headanal[15];
	char m_headmeasure[15];
	DataRecord m_rods;
	DataBase m_database;
	static UINT ReadLaserThread(LPVOID pParam);
	LONGLONG m_count_time;
	ProductParamInfo m_rod_product;
	SlotParamInfo  m_slot_product;
	CLockclipDlg(CWnd* pParent = nullptr);	// 标准构造函数
	virtual ~CLockclipDlg();

	//注册杆径 cp cpk pp ppk
	Monolateral p1_momo_curn, p2_momo_curn, p3_momo_curn;
	Monolateral p1_momo_dayn, p2_momo_dayn, p3_momo_dayn;

	Monolateral p1_momo_curb, p2_momo_curb, p3_momo_curb;
	Monolateral p1_momo_dayb, p2_momo_dayb, p3_momo_dayb;

	//注册锁夹槽 cp cpk pp ppk
	Monolateral s1_momo_curn, s2_momo_curn, s3_momo_curn, s4_momo_curn, s5_momo_curn, s6_momo_curn, s7_momo_curn, s8_momo_curn, s9_momo_curn;
	Monolateral s1_momo_dayn, s2_momo_dayn, s3_momo_dayn, s4_momo_dayn, s5_momo_dayn, s6_momo_dayn, s7_momo_dayn, s8_momo_dayn, s9_momo_dayn;

;   Monolateral s1_momo_curb, s2_momo_curb, s3_momo_curb, s4_momo_curb, s5_momo_curb, s6_momo_curb, s7_momo_curb, s8_momo_curb, s9_momo_curb;
    Monolateral s1_momo_dayb, s2_momo_dayb, s3_momo_dayb, s4_momo_dayb, s5_momo_dayb, s6_momo_dayb, s7_momo_dayb, s8_momo_dayb, s9_momo_dayb;
	


	LRESULT OnCommData(WPARAM wParam, LPARAM lParam);
	BOOL OnSetTimers(INT time);
	//-------------------------------页面函数----------------------------------------------------
	void OnSetWindowSize(LONG nWidth, LONG nHeight);
	void OnHideToTaskbar();
	void OnShowFromTaskbar();
	void OnCloseWindows();

	afx_msg LRESULT OnHideToTaskbar(WPARAM wParam, LPARAM lParam);
	afx_msg LRESULT OnShowFromTaskbar(WPARAM wParam, LPARAM lParam);
	afx_msg LRESULT OnShowTask(WPARAM wParam, LPARAM lParam);
	void ToTray();

	INT OnGetCurIndex();
	BOOL OnLoginOut();
	BOOL OnStartMeasure();
	BOOL OnSendMeasure();
	BOOL OnSendRodMeasure();
	BOOL OnSendSlotMeasure();
	BOOL OnVerifyMeasure();
	BOOL OnDeleteMeasure();
	BOOL OnRestoration();
	BOOL OnContrlCommand(INT index);//1复位,2端面,3急停,4按键
	BOOL OnSendCommand(INT index, INT status);
	BOOL OnSaveRoute(INT forward, INT reverse, INT inch, INT time);
	//======================================MySQL函数=============================================
	BOOL OnInsertAlarmEventrecord(BSTR alarm_type, BSTR handle_content);
	BSTR OnGetAlarmEventrecord(BSTR time);
	BOOL OnInsertAlarmTips(BSTR alarm_content);
	BSTR OnGetProductName(int id);
	BSTR OnGetAlarmTips(BSTR time);
	BSTR OnGetAllProduct();
	BSTR OnSelectProductByID(int id);
	BSTR OnSelectProductInfoToSetPageByID(int id);
	BSTR GetProductAllInfoById(int id);
	BSTR OnUserLogin(BSTR user, BSTR passwd);
	BSTR OnGetUserInfo();
	BSTR OnGetUsers();
	BOOL OnDeleteUserByID(int id);
	BOOL OnInsertUser(BSTR name, BSTR passwd, BSTR team, INT leader, INT role);
	BOOL OnInsertProductParmaer(BSTR valueStr);
	BOOL OnInsertHoseRecord(BSTR valueStr);
	BOOL OnInsertSlotParmaer(BSTR valueStr);
	BOOL OnUpdateProductParmaer(BSTR valueStr);
	BOOL OnUpdateSlotParmaer(BSTR valueStr);
	BSTR GetProductParamer(BSTR product_type);
	BSTR GetSlotParamer(BSTR product_type);
	BOOL OnSendDataRecord(BSTR jsonString);
	BSTR OnGetDataRecordXR(BSTR time);
	BOOL OnDeleteProductByID(int id);
	BSTR OnGetLastProduct();
	BSTR OnGetDataRecord(int id);
	BSTR OnGetMotorControl();
	BSTR OnErrorDataDetection(BSTR jsonString);//SPC
	BSTR OnGetSlotErrorEvent();
	BOOL OnSetMotorHoldPosition();
	BOOL OnDeleteDataRrcord();
	BOOL OnGetResult();
	CHAR OnSendInchParam();
	BSTR SelectDataRecordByTime(BSTR m_time);//给定时间查询
	BSTR SelectDataRecordByRodSelect(BSTR jsonString);
	BSTR GetALLDataRecord(BSTR jsonString);
	BOOL OnUpdateConeParmaer(BSTR valueStr);
	BOOL OnInsertConeParmaer(BSTR valueStr);

	//-------------------------------------锁夹槽函数-----------------------------------------------
	void OnSetParams(double wheelSpeed, double roller, double roddia);
	void OnPrerotation(int contrl, double pre_turns);//预转
	void OnCorotation(int contrl, double cor_turns);//1-正转,2-反转,0-停止
	void OnScram(int contrl);//紧急停止
	void OnDetectAction(int index, int contrl);
	BSTR OnGetLockParams();
	BOOL OnUpdataParmer(BSTR jsonString);

	// 对话框数据
#ifdef AFX_DESIGN_TIME
	enum { IDD = IDD_LOCKCLIP_DIALOG, IDH = IDR_HTML_LOCKCLIP_DIALOG };
#endif

protected:
	// DDX/DDV 支持
	virtual void DoDataExchange(CDataExchange* pDX);
	//2.去掉安全提示框
	virtual BOOL CanAccessExternal();
	// 实现
protected:
	CLockclipDlgAutoProxy* m_pAutoProxy;
	HICON m_hIcon;
	// 生成的消息映射函数
	virtual BOOL OnInitDialog();
	virtual BOOL PreTranslateMessage(MSG* pMsg);
	afx_msg void OnTimer(UINT_PTR nIDEvent);
	afx_msg void OnPaint();
	afx_msg void OnDestroy();
	afx_msg HCURSOR OnQueryDragIcon();

	DECLARE_MESSAGE_MAP()
	DECLARE_DHTML_EVENT_MAP()
	//1.添加宏定义
	DECLARE_DISPATCH_MAP()
};
